/* 可选参数（必须在末尾）和默认参数 */
// function buildName(firstName: string, lastName?: string) {
//     if (lastName)
//         return firstName + " " + lastName;
//     else
//         return firstName;
// }
// let result1 = buildName("Bob");  // works correctly now
// let result3 = buildName("Bob", "Adams");  // ah, just right
// let result2 = buildName("Bob", "Adams", "Sr.");  // error, too many parameters
/* 与普通可选参数不同的是，带默认值的参数不需要放在必须参数的后面，用户必须明确的传入undefined值来获得默认值 */
// function buildName(firstName = "Will", lastName: string) {
//     return firstName + " " + lastName;
// }
// // let result1 = buildName("Bob");                  // error, too few parameters
// // let result3 = buildName("Bob", "Adams");         // okay and returns "Bob Adams"
// // let result2 = buildName("Bob", "Adams", "Sr.");  // error, too many parameters
// let result4 = buildName(undefined, "Adams");     // okay and returns "Will Adams"
// console.log(buildName(undefined, "Adams"));
/* 重载 */
var suits = ["spades", "hearts", "clubs", "diamonds"];
/* 对重载的函数做具体实现 */
function pickCard(x) {
    // Check to see if we're working with an object/array
    // if so, they gave us the deck and we'll pick the card
    if (typeof x == "object") {
        console.log("path a");
        var pickedCard = Math.floor(Math.random() * x.length);
        return pickedCard;
    }
    // Otherwise just let them pick the card
    else if (typeof x == "number") {
        console.log("path b");
        var pickedSuit = Math.floor(x / 13);
        return { suit: suits[pickedSuit], card: x % 13 };
    }
}
var myDeck = [{ suit: "diamonds", card: 2 }, { suit: "spades", card: 10 }, { suit: "hearts", card: 4 }];
var pickedCard1 = myDeck[pickCard(myDeck)];
console.log("card: " + pickedCard1.card + " of " + pickedCard1.suit);
var pickedCard2 = pickCard(15);
console.log("card: " + pickedCard2.card + " of " + pickedCard2.suit);
